package JasPerl::CGI::Response;

use strict;
use warnings;

use parent qw(JasPerl::Response);

sub new {
    my ($class, $cgi) = @_;
    bless { cgi => $cgi }, $class;
}

sub get_content_type {
    return $_[0]->{content_type};
}

sub set_content_type {
    $_[0]->{content_type} = $_[1];
}

sub send_redirect {
    my ($self, $location) = @_;
    warn "-- CGI redirect $location\n";
    unless (exists $self->{init}) {
        print $self->{cgi}->redirect($location);
        $self->{init} = 1;
    }
}

sub get_writer {
    my $self = shift;
    warn "-- CGI get writer\n";
    unless (exists $self->{init}) {
        my $cookie = $self->{cgi}->cookie(
            -name=>'jasperl', -value=> '45',
            -expires=>'+1h', -path=>'/cgi-bin'
            );
        print $self->{cgi}->header(
            -type => $self->{content_type},
            -cookie => $cookie
            );
        $self->{init} = 1;
    }

    # FIXME
    binmode STDOUT, ":utf8";

    return \*STDOUT;
}

1;
